package cn.itlaobing.web.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.GenerationTime;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

import javax.annotation.Generated;
import javax.management.relation.Role;
import javax.persistence.*;
import javax.persistence.criteria.CriteriaBuilder;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Entity
@Table(name = "system_users")
public class SystemUser {

    /*
    * 主键
    * */
    @Id
    @GeneratedValue
    private Long id;

    /*
    * 创建时间
    * */
    @Column(name = "create_time")
    @CreatedDate
    private Date createTime;

    /*
    * 更新时间
    * */
    @Column(name = "update_time")
    @LastModifiedDate
    private Date updateTime;

    /*
    * 逻辑删除
    * */
    @Column(name = "is_delete")
    private Integer isDelete;

    /*
    * 用户状态
    * */
    private Integer status;

    /*
    * 上次登录时间
    * */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_login_time")
    private Date lastLoginTime;

    /*
    * 锁定
    * */
    @Column(name = "is_locked")
    private Integer islocked;
    /*
    * 是否登录
    * */
    @Column(name = "is_login")
    private Integer islogin;
     /*
    * 用户账号
    * */

    @Column(name = "user_acccount")
    private String userAccount;

    /*
    * 用户密码
    * */
    @Column(name = "user_pass")
    private String userPass;


    /*
    * 用户头像
    * */
    @Column(name = "head_image")
    private String headImage;

     /*
    * 真实姓名
    * */
     @Column(name = "user_real_name")
     private String userRealName;

    /*
    * 电话
    * */
    @Column(name = "user_phone")
    private String userPhone;

    //账号 角色关系
    @ManyToMany(fetch=FetchType.EAGER)
    @JoinTable(
            name="system_user_roles",
            joinColumns={@JoinColumn(name="system_account_id",referencedColumnName="id")},
            inverseJoinColumns={@JoinColumn(name="system_role_id",referencedColumnName="id")}
    )
    private Set<SystemRole> roles;
    //记录所有权限
    @Transient
    @JsonIgnore
    private Set<SystemPermission> permissions;


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Integer getIsDelete() {
        return isDelete;
    }

    public void setIsDelete(Integer isDelete) {
        this.isDelete = isDelete;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(Date lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public Integer getIslocked() {
        return islocked;
    }

    public void setIslocked(Integer islocked) {
        this.islocked = islocked;
    }

    public String getUserAccount() {
        return userAccount;
    }

    public void setUserAccount(String userAccount) {
        this.userAccount = userAccount;
    }

    public String getUserPass() {
        return userPass;
    }

    public void setUserPass(String userPass) {
        this.userPass = userPass;
    }

    public String getHeadImage() {
        return headImage;
    }

    public void setHeadImage(String headImage) {
        this.headImage = headImage;
    }

    public String getUserRealName() {
        return userRealName;
    }

    public void setUserRealName(String userRealName) {
        this.userRealName = userRealName;
    }

    public Set<SystemPermission> getPermissions() {
        return permissions;
    }

    public void setPermissions(Set<SystemPermission> permissions) {
        this.permissions = permissions;
    }

    public Set<SystemRole> getRoles() {
        return roles;
    }

    public void setRoles(Set<SystemRole> roles) {
        this.roles = roles;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public Integer getIslogin() {
        return islogin;
    }

    public void setIslogin(Integer islogin) {
        this.islogin = islogin;
    }
}
